import android.content.Context
import android.os.Build
import android.widget.Toast
import com.fake.handwriting.fake_handwriting.Util
import io.flutter.embedding.android.FlutterActivity
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import java.util.jar.Manifest

class Channel(flutterEngine: BinaryMessenger, context:Context): MethodChannel.MethodCallHandler {
    private val batteryChannelName = "fake_handwriting"
    private var channel: MethodChannel
    private var mContext: Context
    init {
        channel = MethodChannel(flutterEngine, batteryChannelName)
        channel.setMethodCallHandler(this)
        mContext = context
    }
    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) = when(call.method){
        "toast"->{
            Toast.makeText(mContext,call.argument("content"),Toast.LENGTH_SHORT).show()
            result.success("")
        }
        "getCacheDir"->{
            result.success("${mContext.cacheDir.path}/")
        }
        "shareFile"->{
            Util.shareFile(mContext,call.argument<String>("path").toString())
            result.success("")
        }
       else->result.notImplemented()
    }
}